#!/usr/bin/env python
# -*- coding:utf-8 -*-
from flask import jsonify, request
from flask_restful import Resource, reqparse
from service.documentService import DocumentService
from utils import commons


class DocumentOtherResource(Resource):
    @classmethod
    def upload_document(cls):
        parser = reqparse.RequestParser()
        parser.add_argument('ppt_id', location='form', required=True, help='ppt_id参数类型不正确或缺失')
        parser.add_argument('file', location='files', required=True, help='file参数类型不正确或缺失')

        kwargs = parser.parse_args()
        kwargs = commons.put_remove_none(**kwargs)

        kwargs['file'] = request.files.get('file')

        res = DocumentService.upload_document(**kwargs)
        return jsonify(code=res['code'], message=res['message'], data=res['data'])